package com.example.demo.Exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2023-02-12
 * Time:9:09
 */
//统一异常处理
//控制器通知类
@ControllerAdvice
public class test {
    //异常处理器
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object halder(Exception e){
        HashMap<String,Object> map=new HashMap<>();
        map.put("state",0);
        map.put("data",null);
        map.put("message",e.getMessage());
        return map;
    }
//    空指针的异常
//    @ExceptionHandler(NullPointerException.class);

}
